-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[SoftDeleteable] Remove dollar sign from cache key #2978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[SoftDeleteable] Remove dollar sign from cache key #2978
Conversation
Hi, do you have any example when it's an issue ? |
In my application (Laminas+Doctrine stack) I'm using this repo's extensions, and for Doctrine I'm using Laminas's filesystem cache. So the cacheId extension metadata will be used in file system cache. Now it throws an error. I've created a quick example where you can reproduce: {
"name": "test/test",
"require": {
"php": "^8.3",
"laminas/laminas-cache-storage-adapter-filesystem": "^3.1.0",
"gedmo/doctrine-extensions": "^3.20.1"
}
} <?php
declare(strict_types=1);
include 'vendor/autoload.php';
use Gedmo\Mapping\ExtensionMetadataFactory;
use Laminas\Cache\Storage\Adapter\Filesystem;
$cacheId = ExtensionMetadataFactory::getCacheId('Foo', 'Bar');
//cacheId is 'Foo_$BAR_CLASSMETADATA';
$fileSystemCache = new Filesystem();
$fileSystemCache->addItem($cacheId, ['some' => 'data']);
//Uncaught Laminas\Cache\Exception\InvalidArgumentException: The key 'Foo_$BAR_CLASSMETADATA' doesn't match against pattern '/^[a-z0-9_\+\-\.]*$/Di' |
Since this library requires a PSR-6 cache, and from what I can tell the Laminas cache doesn't directly implement that PSR (it does provide a decorator for this), is there an issue when you use their PSR-6 decorator with this library? (On a side note, I'd say the From a practical perspective, there isn't an issue with this PR (and presumably improves PSR-6 compatibility by ensuring only characters the spec explicitly says an implementation must support are used). But, it seems that the MongoDB ODM also uses a dollar sign in its cache keys which would imply that ODM and Laminas Cache are incompatible for the same reason. |
@mbabker /** @var StorageAdapterFactoryInterface $storageFactory */
$storageFactory = $container->get(StorageAdapterFactoryInterface::class);
/** @var StorageInterface&FlushableInterface $fileCache */
$fileCache = $storageFactory->create('filesystem', $options);
return new CacheItemPoolDecorator($fileCache); The direct use of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @adambalint-srg!
As you are presenting this change as a fix, please add an entry in the Fixed
section of the changelog, including an explanation about what it fixes.
See: https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/CONTRIBUTING.md#changelog.
Thanks also to @mbabker for the detailed analysis.
@phansys Changelog has been updated |
I think a new rebase is needed since 3.21 is released |
Bumps [hadolint/hadolint-action](https://github.com/hadolint/hadolint-action) from 3.2.0 to 3.3.0. - [Release notes](https://github.com/hadolint/hadolint-action/releases) - [Changelog](https://github.com/hadolint/hadolint-action/blob/master/.releaserc) - [Commits](hadolint/hadolint-action@v3.2.0...v3.3.0) --- updated-dependencies: - dependency-name: hadolint/hadolint-action dependency-version: 3.3.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]>
CHANGELOG.md
Outdated
### Fixed | ||
- SoftDeleteable: Remove dollar sign ($) from the default cache key of soft deleteable metadata - to be compatible with stricter cache key naming conventions (#2978) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the only change in the CHANGELOG.md file, you shouldn't impact 3.21.0 release
Co-authored-by: Vincent Langlet <[email protected]>
@VincentLanglet Sorry for mixing changelog parts. Is it OK now? |
I think it is. It's on @phansys side now |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2978 +/- ##
=======================================
Coverage 78.56% 78.56%
=======================================
Files 169 169
Lines 8803 8803
=======================================
Hits 6916 6916
Misses 1887 1887 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CHANGELOG.md
Outdated
|
||
## [Unreleased] | ||
### Fixed | ||
- SoftDeleteable: Remove dollar sign ($) from the default cache key of soft deleteable metadata - to be compatible with stricter cache key naming conventions (see https://www.php-fig.org/psr/psr-6/#definitions) (#2978) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading the provided description and the referenced definition, I can't see this change as a fix.
The PSR-6 spec about cache keys states the following:
Key - A string of at least one character that uniquely identifies a cached item. Implementing libraries MUST support keys consisting of the characters A-Z, a-z, 0-9, _, and . in any order in UTF-8 encoding and a length of up to 64 characters. Implementing libraries MAY support additional characters and encodings or longer lengths, but must support at least that minimum.
This does not mean that characters other than A-Z
, a-z
, 0-9
, _
, and .
are not allowed or discouraged. It confirms that at least these must be supported as minimum.
However, even if the current choice of characters in this library complies with the PSR-6 spec but causes a problem, the Fixed
section MUST explicitly and clearly state what problem this change is fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phansys
Should I link the Laminas File cache's pattern here?
https://github.com/laminas/laminas-cache-storage-adapter-filesystem/blob/3.2.x/src/FilesystemOptions.php#L26
This was the reason of the whole PR.
In my opinion if PSR6 says about what is the most strict standard, and this library follows this, it can be a fix, but it's your decision of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my take on the changelog entry. It's not a fix per se as it's not directly fixing a bug, so let's call it a change. Also note it doesn't affect only SoftDeleteable as this is changing the base EMF class all extensions use.
### Changed
- All: Removed the dollar sign from the generated cache ID for extension metadata to ensure only characters mandated by PSR-6 are used, improving compatibility with caching implementations with strict character requirements (#2978)
FWIW, doctrine/persistence
originally used $CLASSMETADATA
as its cache salt in the class metadata factory when the doctrine/cache
library was used. It changed to the current __CLASSMETADATA__
value in doctrine/persistence#144 when support for PSR-6 was added and support for the Doctrine Cache library was deprecated. There isn't any explanation in that PR why the salt changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your proposal @mbabker.
@adambalint-srg, could you please rebase the PR and update the changelog according this suggestion?
This PR removes dollar sign ($) from the default cache key. It's not a globally reserved characters in filenames, but there are cases when it can cause problems, as I read. This is why e.g. Laminas's filesystem cache disables this character. I think using
__
instead of_$
isn't a problem, and won't cause any problems.